/**
 * 将数组转换为树结构
 *
 * @param arr
 * @returns {any[]} 树结构数据
 */
export function convertArrayToTree(arr: any[]) {
  const originalArray = arr
  const map: Record<string, any> = {}
  const result: Record<string, any>[] = []
  originalArray.forEach(v => {
    v.children = []
    if (!map[v.resourceId]) {
      map[v.resourceId] = v
    }

    if (v.parentId === -1) {
      v.disabled = false
      result.push(v)
    }
  })
  originalArray.forEach(v => {
    if (map[v.parentId]) {
      v.disabled = false
      map[v.parentId].children.push(v)
    }
  })
  return result
}
